package com.adtech.farmProducts.activities.activity.dialog;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.adtech.farmProducts.R;
import com.adtech.farmProducts.activities.activity.WebViewActivity;
import com.adtech.farmProducts.base.NativeActivity;
import com.adtech.farmProducts.model.Advertising;
import com.adtech.farmProducts.utils.Constants;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.OnClick;
import cn.bingoogolapple.bgabanner.BGABanner;

/**
 * Time:2019/11/7
 * Created by xiaocz
 * Describe 小程序-轮播广告
 */
public class AdvertisingActivity extends NativeActivity {

    @BindView(R.id.banner_guide_content)
    BGABanner mContentBanner;

    private ArrayList<Advertising> list;

    @Override
    protected int getLayoutSourceId() {
        return R.layout.dialog_banner;
    }

    public static void show(Context context, ArrayList<Advertising> list) {
        Intent intent = new Intent(context, AdvertisingActivity.class);
        intent.putParcelableArrayListExtra("ADVERT_LIST", list);
        context.startActivity(intent);
    }

    @Override
    protected boolean initArgs(Bundle bundle) {
        list=bundle.getParcelableArrayList("ADVERT_LIST");
        return super.initArgs(bundle);
    }

    @OnClick({R.id.cancel_btn})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.cancel_btn:
                finish();
                break;
        }
    }

    @Override
    protected void initWidgets() {
        super.initWidgets();
        mContentBanner.setDelegate(new BGABanner.Delegate() {
            @Override
            public void onBannerItemClick(BGABanner banner, View itemView, @Nullable Object model, int position) {
                System.out.println("--点击："+position+model);
                Advertising advertising= (Advertising) model;
                if(advertising!=null && advertising.getHref()!=null && !"".equals(advertising.getHref())){
                    WebViewActivity.show(mContext,advertising.getHref());
                }
            }
        });
    }

    @Override
    protected void initData() {
        mContentBanner.setData(list,null);
        mContentBanner.setAdapter(new BGABanner.Adapter<ImageView,Advertising>() {
            @Override
            public void fillBannerItem(BGABanner banner, ImageView itemView, Advertising model, int position) {
                Glide.with(mContext)
                        .load(model.getImgUrl()).apply(Constants.getOptions())
                        .into(itemView);
            }
        });
    }
}
